package com.example.hello.POJO;

import com.example.hello.views.assignments.Assignments;

import java.util.*;

public class AssignmentPOJO extends POJO {

    public static final String UNASSIGNED = "_unassigned";

    private String description;
    private String track;
    private List<String> badges = new ArrayList<>();
    private Set<String> reviewers = new HashSet<>();
    private int submissionPoints;
    private int reviewPoints;

    public AssignmentPOJO() {
    }

    public AssignmentPOJO(String name, String description) {
        this(name, description, UNASSIGNED, new ArrayList<String>(), -1, -1);
    }

    public AssignmentPOJO(String name, String description, String track, List<String> badges, int submissionPoints, int reviewPoints) {
        this.name = name;
        this.description = description;
        this.track = track;
        this.badges = badges;
        this.submissionPoints = submissionPoints;
        this.reviewPoints = reviewPoints;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getTrack() {
        return track;
    }

    public void setTrack(String track) {
        this.track = track;
    }

    public List<String> getBadges() {
        return badges;
    }

    public void setBadges(List<String> badges) {
        this.badges = badges;
    }

    public void addBadge(String badge) {
        if (!badges.contains(badge)) badges.add(badge);
    }

    public boolean removeBadge(String badge) {
        return badges.remove(badge);
    }

    public boolean hasBadge(String badge) {
        return badges.contains(badge);
    }

    public Set<String> getReviewers() {
        return reviewers;
    }

    public void setReviewers(Set<String> reviewers) {
        this.reviewers = reviewers;
    }

    public void addReviewer(String reviewer) {
        if (!reviewers.contains(reviewer)) reviewers.add(reviewer);
    }

    public boolean removeReviewer(String reviewer) {
        return reviewers.remove(reviewer);
    }

    public boolean hasReviewer(String reviewer) {
        return reviewers.contains(reviewer);
    }

    public int getSubmissionPoints() {
        return submissionPoints;
    }

    public void setSubmissionPoints(int submissionPoints) {
        this.submissionPoints = submissionPoints;
    }

    public int getReviewPoints() {
        return reviewPoints;
    }

    public void setReviewPoints(int reviewPoints) {
        this.reviewPoints = reviewPoints;
    }

    public String toString() {
        String str = "Assignment:\n";

        str += "    _id: " + _id + "\n";
        str += "    name: " + name + "\n";
        str += "    description: " + description + "\n";
        str += "    track: " + track + "\n";
        str += "    badges: " + Arrays.toString(badges.toArray()) + "\n";
        str += "    reviewers: " + Arrays.toString(reviewers.toArray()) + "\n";
        str += "    submissionPoints: " + submissionPoints + "\n";
        str += "    reviewPoints: " + reviewPoints;

        return str;
    }

    public boolean create() {
        return create(Assignments.NAME, this);
    }

    public boolean update() {
        return update(Assignments.NAME + "/" + name, this);
    }

}